RewriteRule for htaccess using regex

I need to redirect /start to /start/index.html and everything else (/anything) to /index.html

What is the correct regex rewriterule for this?

Thanks

Answers


I need to redirect /start to /start/index.html and everything else (/anything) to /index.html. What is the correct regex rewriterule for this?

You may try this in one .htaccess file at root directory:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI}  !index\.html      [NC]
RewriteRule ^start/(.*)  /start/index.html?$1 [L,NC,QSA]

In the rule, anything is passed as a query to index.php and the QSA flag adds the incoming one when present.

To pass anything as a path segment, replace ?$1 with /$1 and remove the QSA flag. It's useless, as any incoming query will be appended automatically.

For permanent redirection, replace [L,NC,QSA] with [R=301,L,NC,QSA]


Rewrite condition is needed:

RewriteRule ^start/?$ /start/index.html [R]

RewriteCond %{REQUEST_URI} !^/start/?$
RewriteRule ^([a-zA-Z0-9_-]+)/?$ /index.html [R]

Please considered this link about the [R] flag: http://stackoverflow.com/a/15999177/2007055


Need Your Help

Pass Parameters in VBA HTTP Post Request

html http vba excel-vba xmlhttp

I'm trying to do a simple post request on the main search bar of http://forums.egullet.org/. (This is one example, but I'm trying to build a tool that will work with many.)

SQL Oracle: Replace an empty result with word

sql oracle select case

I'm working on this problem for several days. I have a oracle database.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.