I know this question may have been asked many times before and I may be down-voted a lot but trust me, this was my last resort after testing and reading many articles on google.
I have the url /index.php?action=gametypes&mode=control-point which I would like to rewrite to /gametypes/control-point.
I've tried
RewriteEngine On
RewriteRule ^gametypes/([^/\.]+)/?$ index.php?action=gametypes&mode=$1[L]
Now when I visit /gametypes/control-point I get a 404 not found and the URL shows rewrites to localhost/thecoremc/gametypes/control-point/index.php. It's a 404 because there is no index.php. Any idea what I could use to successfully load the page?
Extra info: I'm running my localhost with the domain localhost/thecoremc/ and apache 2.4.4
Thanks!
You could try this instead...
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)\.html$ /index.php?action=$1&mode=$2 [L]
I used a dummy-domain, which was http://www.domain.com/index.php?action=gametypes&mode=control-point to achieve this.
Based on your comment, try this...
RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)\.html$ /thecoremc/index.php?action=$1&mode=$2 [L]
which is based on: http://localhost/thecoremc/index.php?action=gametypes&mode=control-point
You can use this code in your /thecoremc/.htaccess file:
RewriteEngine On
RewriteBase /thecoremc/
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?action=$1&mode=$2 [L,QSA]
Try this. This might be helpful for your work.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=(.*)&name=(.*)$
RewriteRule ^articles\.php$ /article/%1/%2? [R=301]
RewriteRule ^article/([^-]+)/([^-]+)$ /articles.php?article_id=$1&article_name=$2 [L]
The above code will redirect
localhost/a1/articles.php?id=10&name=xyz
to
localhost/article/10/xyz
Try this:
Options +FollowSymLinks
RewriteEngine on
RewriteRule gametypes/(.*)/(.*)/ index.php?action=$1&mode=$2
Related
Before I start, I'd like to say that I did search for topics similar to my problem and tried all solutions provided, but my problem still persists, so I had to post my own question.
Anyway, inside our wordpress site, we have a page called site.com/shops and we want to put a parameter to it. After that we want to use a rewrite rule so that site.com/tx will load site.com/?pagename=shops&state=tx. We put this on our .htaccess:
RewriteRule ^tx(/)?$ index.php?pagename=shops&state=tx[L]
For some reason this doesn't work like we intended. I checked to see if index.php was the problem by changing it to
RewriteRule ^tx(/)?$ test.php?pagename=shops&state=tx[L]
That worked, so I believe the problem is that it doesn't work if index.php was used. How do I make it work using index.php? TIA.
Replace .htaccess code with below code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress_test/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress_test/index.php [L]
</IfModule>
i hope it's works
I have a slight problem.
I have a site that uses these formats for viewing certain PHP documents:
domainname.com/server.php?id=14
domainname.com/changeserver.php?id=14
domainname.com/customize.php?id=14
I would like to make these:
domainname.com/server/14
domainname.com/changeserver/14
domainname.com/customize/14
I also have various URLs such as /index.php and /login.php I would like to clean up.
If someone were to type the original URL, such as /server.php?id=14, I would like it to redirect to it's clean URL.
If anyone can provide me with a config or help me along the way to making one that can do this, it would be greatly appreciated.
To prevent an infinite loop while externally redirecting the ugly url to the clean url and internally rewriting it back to the ugly url, you can use the THE_REQUEST trick.
#External redirect
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /(server|changeserver|customize)\.php\?id=([^&]+)\ HTTP
RewriteRule ^ /%2/%3? [R,L]
#Change above to [R=301,L] once all rules work as expected
#Internal rewrite
RewriteRule ^(server|changeserver|customize)/(.*)$ /$1?id=$2 [L]
You need to rewrite your URLs in .htaccess file.
RewriteEngine On
RewriteRule ^server/(.*)$ server.php?id=$1 [R=301,L]
here is a good guide on URL rewriting
http://www.addedbytes.com/articles/for-beginners/url-rewriting-for-beginners/
In this case you have to use a 301 Redirect of URLS. Here is an example:
Redirect
www.example.com/a1/articles.php?id=1&name=abc
to
www.example.com/article/1/abc
For this you have to modify the .htaccess file with the following:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=(.*)&name=(.*)$
RewriteRule ^articles\.php$ /article/%1/%2? [R=301]
RewriteRule ^article/([^-]+)/([^-]+)$ /articles.php?article_id=$1&article_name=$2 [L]
RewriteEngine On
RewriteRule ^server/([A-Za-z0-9-_,()'+]+)?$ server.php?id=$1
RewriteRule ^changeserver/([A-Za-z0-9-_,()'+]+)?$ changeserver.php?id=$1
RewriteRule ^customize/([A-Za-z0-9-_,()'+]+)?$ customize.php?id=$1
To adapt to your code. Here is the answer.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=(.*)$
RewriteRule ^server\.php$ /server/%1? [R=301]
RewriteRule ^server/([^-]+)$ /server.php?id=$1 [L]
Check the Above code. I think this will help you.
I am trying to redirect www.mysite.com/movie/name to www.mysite.com/movie/?url=name
for this I have added htaccess in movie/ folder, the code I have added is below:
RewriteEngine On
RewriteBase /movie/
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+).html$ index.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?id=$1
I am unable to redirect it, could anybody suggest me the right way to accomplish this?
Just a small change and it should work..
Try below code and let me know whether it worked for you or not..
RewriteEngine On
RewriteRule ^([a-zA-Z0-9-/]+).html$ index.php?id=$1
RewriteRule ^([a-zA-Z0-9-/]+).html/$ index.php?id=$1
Hope it helps...
First off, you only need to write command RewriteEngine On once.
Besides, replace last rule for
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?id=$1
The fault was in the last backslash.
I'm doing a website (for portuguese speaking countries) that displays phrases one at a time.
I would like to have simpler non-dynamic addresses for the site to be SEO friendlier and easier to memorize to the user. So my problem is this, and thanks in advance for all the help possible:
nfrases.com/ -> completely random phrase (don't need changing this!)
nfrases.com/index.php?id_frase=2222 -> phrase with ID (wanted this to be nfrases.com/2222)
nfrases.com/tag.php?tag_nome=amor -> random phrase with tag_nome (want: nfrases.com/amor)
nfrases.com/tag.php?tag_nome=amor&id_frase=2222 -> specific phrase with tag=amor (want: nfrases.com/amor/2222)
I think this is a noob question about mod_rewrite but that's exactly what I am! :D Already made several tries with the few knowledge I have but either i got 404 pages either the parameters wouldn't be received by the $_GET['tag_nome'] or $_GET['id_frase'].
The actual htaccess I have is this but it isn't working:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.nfrases.com$
RewriteRule ^(.*)$ http://www.nfrases.com/$1 [R=301]
RewriteRule ^([0-9]+)(.*) index.php?id_frase=$1
RewriteRule ^(.*)/([0-9]+) tag.php?tag_nome=$1&id_frase=$2 [L,QSA]
Can you guys help me?
Thanks again for everything! I appreciate your help.
The following rewrite rules work for me on a RewriteRule tester:
#removes trailing slash
#/vida/222/ becomes /vida/222
#/222/ becomes /222
RewriteRule ^(.+)/$ /$1 [R=301]
#/222 silently rewrites to /index.php?id_frase=222
RewriteRule ^([0-9]+)$ index.php?id_frase=$1 [L]
#/vida silently rewrites to /index.php?tag_nome=vida
RewriteRule ^([a-zA-Z-]+)$ index.php?tag_nome=$1 [L]
#/vida/222 silently rewrites to /index.php?tag_nome-vida&id_frase=222
RewriteRule ^([^/]+)/([0-9]+)$ tag.php?tag_nome=$1&id_frase=$2 [L]
You may want something like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
In this case, nfrases.com/2222 will rewrited as index.php/2222. This easily allows base routing in your index.php file. For more advanced routing, it may be faster and easier to use a good framework. Take a look at FuelPHP (http:www.fuelphp.com) or CodeIgniter (http://www.codeigniter.com).
I'm sure that's been asked zillions times but i can't get it to work,
i'm trying to rewrite a url with querystring, my url is for example:
http://example.com/articles/index.php?keyword=book
and i want to be accessible from
http://example.com/articles/keyword/book/
I google it and i didn't have any luck,
am i on the right track? i got this:
RewriteCond %{QUERY_STRING} ^keyword=(.*)$ [NC]
RewriteRule ^/articles/index.php$ /articles/keyword/$1 [NC,L,R=301]
UPDATE
this is working fine
RewriteEngine On
Options +FollowSymLinks
RewriteBase /
RewriteRule ^.*/(\w+)\b$ /articles/index.php?keyword=$1
It should work:
RewriteRule ^articles/keyword/(.*)/?$ index.php?keyword=$1
If not, please tell me ;)