http://localhost/frontend_dev.php/1
Why is the above request redirected to frontend_dev.php instead of index.php?
I've read the .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
# uncomment the following line, if you are having trouble
# getting no_script_name to work
#RewriteBase /
# we skip all files with .something
#RewriteCond %{REQUEST_URI} \..+$
#RewriteCond %{REQUEST_URI} !\.html$
#RewriteRule .* - [L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
If I'm understanding it correctly,if the requested file doesn't exist,it should be redirected to index.php,how can frontend_dev.php be run in the case above?
You have specified http://localhost/frontend_dev.php/1 as the URL - Apache simply serves up frontend_dev.php as you are explicitly asking for that file in the URL. Change your URL to http://localhost/index.php/1 to see the production controller.
The rewrite rules deal only with URLs that don't mention a front controller at all, ie. http://localhost/1 - the rewrite rules are not being parsed at all for the URL you initially provided, as Apache detected the frontend_dev.php file and found no matching rewrite rule to parse.
Simple. Because frontend_dev.php does exist, it is executed. And no redirect is performed.
Related
i am new to .htaccess usage and tried to learn through online resources but however i write it the rules negate each other and am having a hard time writing a good enough .htaccess file below is my current .htaccess file which works fine for some pages like removing extensions and rewriting subdomains please check below
## Flag for GoDaddy
Options +MultiViews
RewriteBase /
## Remove extensions
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !=f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
## Redirect from extensions to non-extensions
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]
## Redirect Pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^post/([a-zA-Z0-9-/]+)$ /post.php?ps=$1
RewriteRule ^([a-zA-Z0-9-/]+)$ post-files.php?ps=$1 [L,QSA]
## Server Only
## Redirect from www - non-www
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://$1/$1 [R=301,L]
## SSL Redirect
## RewriteEngine On
## RewriteCond %{HTTPS} ≠On
## RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
## Create Error Pages
ErrorDocument 404 /errors/404.html
ErrorDocument 403 /errors/403.html
ErrorDocument 500 /errors/500.html
## Redirect non-existing pages to index.php
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Above is the .htaccess am currently using and i got it through tutorials from youtube it works good and redirects files.php to files only which am happy with but
as you can see above this line RewriteRule ^post/([a-zA-Z0-9-/]+)$ /post.php?ps=$1 and the line below it are not passing through the ps but they show 404 page
i want the results to be domain.com/post-file-slug to go to exactly file domain.com/post-file.php?ps=post-slug-here for rule RewriteRule ^([a-zA-Z0-9-/]+)$ post-files.php?ps=$1 [L,QSA]
and
domain.com/post/post-slug-here to go to exactly domain.com/post.php?ps=post-slug-here for rule
RewriteRule ^post/([a-zA-Z0-9-/]+)$ /post.php?ps=$1
I was working on this for 2 days now hopefully fix it soon. Thanks
## Flag for GoDaddy
Options +MultiViews
In what way is this a "flag for GoDaddy"? Enabling MultiViews will cause the ps URL parameter not to be passed to the post.php script. You need to ensure that MultiViews is disabled for the later rewrites to work as intended. ie.
Options -MultiViews
MultiViews (part of mod_negotiation) essentially enables extensionless URLs. It will result in a request for /post/post-slug-here to be "rewritten" to /post.php/post-slug-here before your mod_rewrite directive is processed, so it never matches and never rewrites the request to include the ps URL parameter.
## Remove extensions
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !=f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
## Redirect from extensions to non-extensions
RewriteCond %{THE_REQUEST} \s/+(.+?)\.php[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]
It is currently MultiViews that is allowing your extensionless URLs to work. The first condition (RewriteCond directive) above is incorrect. It should be !-f (not a file), not !=f (does not equal "f" - always true). However, this is still "wrong", as you need to check that the .php file exists before rewriting the request. If you simply rewrite all requests that do not map to a file (which is what you are trying to do here) then the later rewrites to post.php, post-files.php and index.php will not be processed as intended.
The regex \s/+(.+?)\.php[\s?] in the second condition is not strictly correct as it will result in a malformed redirect if .php occurs in the query string when it is omitted in the URL-path. eg. A request for /foo?bar.php would result in a redirect to /foo?bar when there should be no redirect at all in this instance. The regex needs to capture the URL-path only, so change the subpattern (.+?) to ([^?]+) instead.
These two rules are also the wrong way round. The external redirect should be first. As a general rule, external redirects should always go before internal rewrites.
It should be like this instead:
## Remove extensions
## Redirect to remove ".php" extension
RewriteCond %{THE_REQUEST} \s/+([^?]+?)\.php[\s?] [NC]
RewriteRule \.php$ /%1 [R=301,NE,L]
# Rewrite to append ".php" extension if corresponding ".php" file exists
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^.]+)$ $1.php [L]
You should already be linking to the file without the .php extension. The redirect to remove the .php extension is for SEO only when changing an existing URL structure.
No need to backslash-escape a literal dot when used inside a regex character class. The NC flag was superfluous here.
## Redirect Pages
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^post/([a-zA-Z0-9-/]+)$ /post.php?ps=$1
RewriteRule ^([a-zA-Z0-9-/]+)$ post-files.php?ps=$1 [L,QSA]
RewriteCond directives only apply to the first RewriteRule directive that follows. So, the second rule above is processed unconditionally - is that the intention?
In fact, those two condition are probably superfluous. The regex would already appear to exclude actual files since the regex excludes dots. And do you need to be able to access filesystem directories directly?
The character class [a-zA-Z0-9-/] is "confusing". The last hyphen is seen as a literal hyphen (which is presumably the intention), but at first glance it can look like a range specifier (as used earlier in the character class). To avoid confusion when matching a literal hyphen inside a character class, either backslash-escape it, or move it to the first or last character in the character class. eg. [a-zA-Z0-9/-].
You are also missing the L flag from the first rule. (You've included it on the second.) Do you also need the QSA flag? (ie. Are you expecting additional URL parameters on the initial request?)
Having revised the "extension removal" rules above, this does not matter so much, but these rules that rewrite the request to post.php and post-files.php should really be above the "extension removal" rules.
## Redirect from www - non-www
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://$1/$1 [R=301,L]
This rule is incorrect and in the wrong place. Canonical redirects (www to non-www and HTTP to HTTPS) should generally be above other rules. As mentioned above, redirects before rewrites.
But this rule is also wholly incorrect. $1 is a backreference to the first captured subpattern in the RewriteRule, so http://$1/$1 will naturally result in a malformed redirect. The first backreference should be %1 (to the last matched CondPattern) to match the requested hostname. Ordinarily, you should also be redirecting to HTTPS here, not HTTP. For example, the rule should read:
:
RewriteRule (.*) https://%1/$1 [R=301,L]
The ^ and $ surrounding the RewriteRule pattern are superfluous since regex is greedy by default.
## SSL Redirect
## RewriteEngine On
## RewriteCond %{HTTPS} ≠On
## RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Although commented out, it is also incorrect. It needs to go before the other rewrites. It should go at the top of the file if implementing HSTS or after the www to non-www redirect if not (and minimising the number of redirects).
The CondPattern in the preceding condition should be !on, not ≠On (which is wholly invalid on two counts... ≠ is not valid and the comparison is case-sensitive. HTTPS will always be lowercase.)
You are also missing the R=301 and L flags.
No need for a capturing group in the RewriteRule pattern, since this is not being used in the substitution string. ^ would suffice (and be more efficient) instead of (.*).
## Create Error Pages
ErrorDocument 404 /errors/404.html
ErrorDocument 403 /errors/403.html
ErrorDocument 500 /errors/500.html
For readability, you should define your custom error documents at the top of the file. (Technically, it doesn't matter.)
## Redirect non-existing pages to index.php
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
For readability you should define the Options together at the top of the file (with -MultiViews). For example:
Options -MultiViews -Indexex +SymLinksIfOwnerMatch
(Disabling Indexes - auto-generated directory listings - is a good idea.)
You do not need to repeat the RewriteEngine directive. (Only the last instance of this directive does anything.) It is logical to place this rule near the top of the file, before your first mod_rewrite directive. (Although technically, the position of this directive in the file does not actually matter.)
Aside: You should be consistent in the prefix you use on your internal rewrites. On some rules you include the slash prefix (eg. /post.php), and on some you have omitted it (post-files.php). You have defined RewriteBase / (which isn't strictly required here as it happens) - RewriteBase only applies to relative substitution strings (ie. when the slash prefix is omitted).
UPDATE:
also i have file i want to exclude like 404.php in root directory from how do i exclude somefiles from the redirect. when i sent ajax to backend php file it redirected to homepage and failed to retrieve data.
To exclude specific files you would add a rule like the following, after the canonical redirects:
# Exclude "/404.php" from stripping the ".php" extension
RewriteRule ^404\.php$ - [L]
Generally, once you go extensionless for .php files you should be extensionless everywhere. So, there should be no unexpected redirects. The redirect is really only for SEO.
With regards to your AJAX requests, if you are making POST requests, then you could simply exclude all POST requests from further processing. For example:
# Prevent further processing of POST requests to ".php" files
RewriteCond %{REQUEST_METHOD} POST [NC]
RewriteRule \.php$ - [L]
Alternatively (or as well as), if your AJAX requests are setting a custom HTTP request header then you can check for this as well.
Summary
Bringing the above points together, it should look like this:
## Disable MultiViews and Indexes
Options -MultiViews -Indexes +SymLinksIfOwnerMatch
## Create Error Pages
ErrorDocument 404 /errors/404.html
ErrorDocument 403 /errors/403.html
ErrorDocument 500 /errors/500.html
RewriteEngine On
RewriteBase /
#### Canonical redirects
## SSL Redirect
## RewriteCond %{HTTPS} !on
## RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
## Redirect from www - non-www
## >>> CHANGE TO "HTTPS://"
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule (.*) http://%1/$1 [R=301,L]
#### Rewrite Pages
RewriteRule ^post/([a-zA-Z0-9/-]+)$ post.php?ps=$1 [QSA,L]
RewriteRule ^([a-zA-Z0-9/-]+)$ post-files.php?ps=$1 [QSA,L]
#### Exceptions
## Exclude "/404.php" from stripping the ".php" extension
RewriteRule ^404\.php$ - [L]
## Prevent further processing of POST requests to ".php" files
RewriteCond %{REQUEST_METHOD} POST [NC]
RewriteRule \.php$ - [L]
#### Remove extensions
## Redirect to remove ".php" extension
RewriteCond %{THE_REQUEST} \s/+([^?]+)\.php[\s?] [NC]
RewriteRule \.php$ /%1 [R=301,NE,L]
## Rewrite to append ".php" extension if corresponding ".php" file exists
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^.]+)$ $1.php [L]
## Redirect non-existing pages to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
I have a directory structure as follows:
.htaccess
api.php
template/index.html
When calling domain.com/api/someendpoint, the request is forwarded to api.php.
# enable apache rewrite engine
RewriteEngine on
# Deliver the folder or file directly if it exists on the server
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteCond %{REQUEST_FILENAME} !-d
# Push every request to api.php
RewriteRule ^(.*)$ api.php [QSA]
now, when calling domain.com, the request should be called to the index.html in the template directory:
RewriteCond %{REQUEST_URI} ^$
RewriteRule . template/index.html [QSA]
this does not work, the directoryListening is always displayed.
What is the correct way to get the index.html?
RewriteCond %{REQUEST_URI} ^$
RewriteRule . template/index.html [QSA]
The RewriteRule pattern (ie. .) unnecessarily matches everything except the document root. And the REQUEST_URI server variable always starts with a slash, so the condition will never match anyway. So, basically, the rule is doing nothing
To rewrite just the root then you just need a single rule in .htaccess:
RewriteRule ^$ template/index.html [L]
Ideally, this would go before your existing rewrites for your API, although it doesn't strictly matter since the other rewrites do not rewrite the root directory (because of the restrictive conditions).
# Push every request to api.php
RewriteRule ^(.*)$ api.php [QSA]
Should everything really be sent to api.php, or perhaps just URLs that start /api/, as in your example? At the very least, you should be using the + quantifier, not *, since you want to exclude requests for the document root (currently, the 3rd condition is blocking requests to the document root from being rewritten).
Note that if your URLs are of the form /api/someendpoint and you are rewriting to /api.php then you need to ensure that MultiViews is disabled at the top of the .htaccess file:
Options -MultiViews
Specifically, I want to redirect all non-www pages to www, while also running an index.php file located in my root directory. To solve both of these problems I am using .htaccess.
I have already set up my site to run the PHP file to run in every directory. But the moment I add redirection from non-www to www it breaks.
The problem seems to be, that the multiple rewrite rules conflict with each other. Either one runs and the other does not, or the site just responds with a 500 error.
My question is, should multiple Rewrite rules be "combined" into one? Or am I just using those multiple rules wrong? (Or is it just some strange syntax thing I messed up? I have been working on this for a while haha)
Any help is very much appreciated.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L,QSA]
# Redirect to www.
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
</IfModule>
I found this works:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L] #if not already index.php
RewriteCond %{REQUEST_FILENAME} !-f #only if NOT a FILE (directory / non-existent file)
RewriteRule . /index.php [L] #redirect to index.php
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*) https://www.example.com/%{REQUEST_FILENAME} [R=301,L] #redirect to https://www
</IfModule>
This cannot possibly "work" as written, as there are a number of errors:
You are missing the opening <IfModule mod_rewrite.c> directive. However, this <IfModule> wrapper is not required anyway and should be removed.
Line-end comments are not supported by Apache. Specifically, the following line will result in a 500 error due to "bad flag delimiters":
RewriteCond %{REQUEST_FILENAME} !-f #only if NOT a FILE (directory / non-existent file)
(UPDATE: If you are not seeing a 500 error response here, it's possible you are on a LiteSpeed server; not Apache? On LiteSpeed, this line-end comment appears to work as intended!)
Your external redirect (at the end) that redirects to www never gets processed for anything other than requests for directories (including the root) or real files (except index.php). This redirect needs to go first, before the existing rewrites. However, see the next point...
You are incorrectly using REQUEST_FILENAME (the absolute filesystem path) in the target URL - this will result in a malformed redirect. You could use the REQUEST_URI server variable instead (full URL-path), but note that you also have a double slash issue. So, it would need to be rewritten like the following instead:
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301,L]
Minor points:
The RewriteBase is not being used here and could be safely removed. (Unless you have other directives that use this?)
Summary
Bringing the above points together we have:
RewriteEngine On
# Redirect to https://www
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Stop here if already index.php
RewriteRule ^index\.php$ - [L]
# Only if NOT a FILE (non-existent file)
RewriteCond %{REQUEST_FILENAME} !-f
# Rewrite to index.php (in the document root)
RewriteRule . /index.php [L]
Note that this still rewrites directories to /index.php, contrary to what your comment stated.
Test first with a 302 (temporary) redirect to avoid potential caching issues.
You will need to clear your browser cache before testing.
After lots of tinkering/research, I found this works:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L] #if not already index.php
RewriteCond %{REQUEST_FILENAME} !-f #only if NOT a FILE (directory / non-existent file)
RewriteRule . /index.php [L] #redirect to index.php
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(.*) https://www.example.com/%{REQUEST_FILENAME} [R=301,L] #redirect to https://www
</IfModule>
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
I am working on a project in which url Rewriting was done. Here is the link of the old uri
http://www.mysite.pk/jobs/search/faisalabad/all-cats
But now in the new url I have changed it to
http://www.mysite.pk/jobs/pakistan/faisalabad/all-cats
what I want to do is to change the redirect all the url's whcih have http://www.mysite.pk/jobs/search/ search after job in them to the
http://www.mysite.pk/jobs/pakistan/
Here is my code of the route
$route["jobs/pakistan"]="vacancies/search";
I have also done
$route["search/pakistan"]="vacancies/search";
My .htaccess file content is
but it is not working
Kindly Helpe me
Thanks in advance
I think the problem are the missing placeholders. Without the placeholders your stated URL
http://www.mysite.pk/jobs/search/faisalabad/all-cats
won't match.
The correct route should look like this:
$route["jobs/pakistan/(:any)"]="vacancies/search";
$route["search/pakistan/(:any)"]="vacancies/search";
This way both jobs/pakistan and search/pakistan are working.
Edit
This RewriteRule will have the same effect when put in the .htaccess file.
RewriteRule ^jobs/search/(.*)?$ http://www.mysite.pk/jobs/pakistan/$1 [L,R=301]
Your .htaccess file then should look similar to this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
###
RewriteRule ^jobs/search/(.*)?$ http://www.mysite.pk/jobs/pakistan/$1 [L,R=301]
# Removes access to the system folder by users.
# Additionally this will allow you to create a System.php controller,
# previously this would not have been possible.
# 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php
</IfModule>
The RewriteRule has following scheme:
RewriteRule [output] [original]
In this case when the "output" (url) starts with jobs/search/ (the ^ marks the beginning and $ the end) everything after this will be redirected to the original. The (.*) marks a reference for any content and will be inserted in the origin in place of $1. The [L,R=301] marks the type of the redirect (the HTTP response status code 301 means Moved Permanently), the L means that after the route is met, the following lines won't be processed.
So I have a dilemma..
Can't figure out how to rewrite this URL to THIS URL:
URL=www.EXAMPLE.com/users/USERNAME
THIS URL= www.EXAMPLE.com/USERNAME
This isn't my first time using Stack Overflow, but this is my first time actually needing an account to find my answer. I will Thank accordingly.
Thanks,
Nick
EDIT:
RewriteRule ^user/(.*)$ /$1 [R=301,L]
But I get a 404 page, weird I say.
The page redirects successfully, but with a 404 instead.
HTACCESS as follows:
## Mod_rewrite in use.
RewriteEngine On
RewriteRule ^user/(.*)$ /$1 [R=301,L]
## Begin - Rewrite rules to block out some common exploits.
# If you experience problems on your site block out the operations listed below
# This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
## End - Rewrite rules to block out some common exploits.
## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
## End - Custom redirects
##
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root).
##
# RewriteBase /
## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.
[UPDATE 4/08/13]
So after a while I have figured out that the only way an extension I am using works alongside Joomla! You need to use a separate extension called sh404sef to make this work. So in a nut shell, no use editing the HTACCESS file like I thought. Ended up spending the 40 bucks and it worked instantly. HAHA
This should answer your question
RewriteRule ^users/(.*)$ $1
Source: .htaccess rewrite from subdirectory to root
A site i find useful with .htaccess url rewriting is:
http://roshanbh.com.np/2008/03/url-rewriting-examples-htaccess.html
The example:
Rewriting yoursite.com/user.php?username=xyz to yoursite.com/xyz
Have you checked zorpia.com.If you type http://zorpia.com/roshanbh233
in browser you can see my profile over there. If you want to do the
same kind of redirection i.e http://yoursite.com/xyz to
http://yoursite.com/user.php?username=xyz then you can add the
following code to the .htaccess file.
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ user.php?username=$1
So in your case you could go for:
RewriteRule ^users/([a-zA-Z0-9_-]+)$ user.php?username=$1
RewriteRule ^users/([a-zA-Z0-9_-]+)/$ user.php?username=$1
see https://stackoverflow.com/questions/20610980/mod-rewrite-redirect-except-parked-domain
All www.primary.com go to www.primary.com/webtrees
Options -Indexes +SymLinksIfOwnerMatch
RewriteEngine on
RewriteBase /
RewriteCond $1 !^parked.com/
RewriteCond $1 !^piwik/
RewriteCond $1 !^wordpress/
RewriteCond $1 !^marker.htm
RewriteCond %{REQUEST_URI} !^/webtrees/
RewriteRule ^(.*)$ /webtrees/$1 [L]