Currently Implementing .amp pages so I copied the url rewrite rules on the same htaccess file. Except one, all is working..
NORMAL version
RewriteRule ^tours/reviews$ reviews.php [QSA,L] **works**
RewriteRule ^tours/reviews-(.*)$ reviews.php?git=$1 [QSA,L] **works**
AMP Version
RewriteRule ^tours/reviews.amp$ reviews.amp.php [QSA,L] **works**
RewriteRule ^tours/reviews-(.*).amp$ reviews.amp.php?git=$1 [QSA,L] **does not work**
Tried escaping - or . did not solve it.
When I get rid of "-" in the URL, it works.. I am confused..
Any ideas ?
Related
With .htaccess i can't get working such link:
/quiz/results/solution-one/?email=myemail#domain.com
into
/results.php?level=4&email=myemail#domain.com
(solution-one should turn into level=4)
I have spend a few hours building .htaccess code:
Rewriterule ^quiz\/results\/solution-one/(.*)/?$ /var/www/domain.com/public_html/results.php?level=4$1 [QSA,L]
Or this one:
Rewriterule ^quiz\/results\/solution-one/([=#.a-zA-Z-]*) /var/www/domain.com/public_html/results.php?level=4&$1 [QSA,L]
But it doesn't work.
Thanks in advance!
Try with:
RewriteEngine on
Rewriterule ^quiz/results/solution-one/?$ results.php?level=4 [NC,QSA,L]
Without file path, but relative to root. And without test for query string (not part of Rewriterule test uri)
i am working on project, which is running XAMPP localhost and PHP MYSQLI,
my question : how i replace "?","=" signs with "/" slash. ?
like, my url is "archive?date=2017-06-02&p=4"
and i want to force it "archive/2017-08-02/4"
i found many codes on stackoverflow and some other sites, but that are not working for me.
if codes are working then, CSS files and GET method doesn't work on my project.
complete code of .htaccess is given below.
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([^=]*)=([^=]*)=(.*) /$1/$2/$3 [N]
RewriteRule ^([^=]*)=([^=]*)$ $1/$2 [L]
RewriteRule ^home index.php [NC,L]
RewriteRule ^archive archive.php [NC,L]
RewriteRule ^about about.php [NC,L]
RewriteRule ^article article.php [NC,L]
RewriteRule ^news news.php [NC,L]
RewriteRule ^video videos.php [NC,L]
RewriteRule ^video?vid=([0-9]+) videos.php?q=$1 [NC,L]
RewriteRule ^article?num=([0-9]+) article.php?num=$1 [NC,L]
RewriteRule ^editorial?num=([0-9]+) editorial.php?num=$1 [NC,L]
RewriteRule ^news?news=([0-9]+) news.php?news=$1 [NC,L]
You cannot check against the query string in a rewrite rule. You need rewrite conditions for that:
RewriteCond %{QUERY_STRING} date=([^&]+)&p=(.+)
RewriteRule ^archive/? /archive/%1/%2?
Demo here: http://htaccess.mwl.be?share=81e85c09-d505-5206-ab14-6c5059107808
If you want to actually redirect just add [R=301,L] to the end of the RewriteRule.
However, looking at the above I suspect you have your script sitting listening at /archive/index.php?data=foo&p=bar but want URLs to be like /archive/date/p, ie pretty.
This is actually a very common misconception about how htaccess URL rewrites work when you first get into them.
RewriteRules will mask or redirect URLs for you but they cannot change the underlying location a script is located at and thus the address used to pass it information.
In other words - you can mask /archive/index.php?data=foo&p=bar as /archive/date/p so that requests made to /archive/date/p resolve to /archive/index.php?data=foo&p=bar, but you cannot make it so that if you enter /archive/index.php?data=foo&p=bar as URL you have the URL change to /archive/date/p while still serving content from /archive/date/p. It has to be either or.
If this all sounds about right my advice would be as follows:
First, put your code into a different file, say /archive/script.php.
Next add the following to your htaccess:
RewriteCond %{QUERY_STRING} date=([^&]+)&p=(.+)
RewriteRule ^archive/? /archive/%1/%2? [R=301,L]
RewriteRule ^archive/([^/]+)/([^/]+) /archive/script.php?date=$1&p=$2
Note that the first two lines are the same as before, but now there is a new line that looks for the masked URL format of /archive/date/p and sends it off to the actual script, which is handled by the new RewriteRule.
The behaviour of the new rule is demoed here: http://htaccess.mwl.be?share=06751667-f16f-5c13-91eb-dd5cffdc6db3
Hope this makes sense / helps.
I have a little problem with htaccess redirection, I have an issue which i can't figure out.
www.old.com/sub should direct to: www.new.com/page/
BUT
all the subpages of www.old.com/sub (www.old.com/sub/1, www.old.com/sub/2), should redirect to www.new.com/category/1, www.new.com/category/2 etc. (insted of page)
But how?
What I tried (i assumed this should work, but it didn't):
RewriteEngine on
RewriteRule ^sub/$ http://www.new.com/page/ [R=301,L]
RewriteRule ^sub(/.*)?$ http://www.new.com/category/$1 [R=301,L]
note; it is part of a large list of redirections, so it should not affect other redirections in this htaccess file.
That work with:
RewriteEngine on
RewriteRule ^sub/?$ http://www.new.com/page/ [R=301,L]
RewriteRule ^sub/(\d+)/?$ http://www.new.com/category/$1 [R=301,L]
You can change (\d+) to (.+) if you do not use numbers only after sub/
I want to rename the following URLs to SEO friendly URL.
Change the following URL : http://www.peacockgirls.com/index.php?page=1 into http://www.peacockgirls.com
Change the following URL : http://www.peacockgirls.com/index.php?page=2 into http://www.peacockgirls.com/greece-escort
Change the following URL : http://www.peacockgirls.com/index.php?page=3 into http://www.peacockgirls.com/athens-escort
Change the following URL : http://www.peacockgirls.com/index.php?page=4 into http://www.peacockgirls.com/bookings
Change the following URL : http://www.peacockgirls.com/index.php?page=5 into http://www.peacockgirls.com/jobs
Change the following URL : http://www.peacockgirls.com/index.php?page=6 into http://www.peacockgirls.com/contact-us
Change the following URL : http://www.peacockgirls.com/index.php?page=24 into http://www.peacockgirls.com/articles
Change the following URL : http://www.peacockgirls.com/index.php?page=7 into http://www.peacockgirls.com/links
Change the following URL : http://www.peacockgirls.com/index.php?profile=22 into http://www.peacockgirls.com/profile/aleena
Change the following URL : http://www.peacockgirls.com/index.php?profile=40 into http://www.peacockgirls.com/profile/fabiana
Change the following URL : http://www.peacockgirls.com/index.php?profile=48 into http://www.peacockgirls.com/profile/sabrina
Change the following URL : http://www.peacockgirls.com/index.php?profile=69 into http://www.peacockgirls.com/profile/suzanna
Change the following URL : http://www.peacockgirls.com/index.php?profile=63 into http://www.peacockgirls.com/profile/anna
Change the following URL : http://www.peacockgirls.com/index.php?profile=70 into http://www.peacockgirls.com/profile/sam
Change the following URL : http://www.peacockgirls.com/index.php?profile=61 into http://www.peacockgirls.com/profile/Larissa&Samantha
Change the following URL : http://www.peacockgirls.com/index.php?profile=54 into http://www.peacockgirls.com/profile/McKenzie
Change the following URL : http://www.peacockgirls.com/index.php?profile=29 into http://www.peacockgirls.com/profile/valery
If you show me 4 or 5 URLs renaming techniques using .htaccess, I shall do remaining URLs. I was given this task, but can't do it.
With that kind of tasks I would go for RewriteMap.
You could use two separate map text files (for better file management): one for profiles and one for pages (any new file for other type of rewrites).
Your .htaccess could be setup that way:
RewriteMap userid txt:/etc/apache2/useridmap.txt
RewriteRule ^/index.php?page=(.+) /profile/${userid:$1} [L,R=301]
Map text file format is as follows:
# Comment line
MatchingKey SubstValue
MatchingKey SubstValue # comment
In your case, profiles text file could look as follows:
22 aleena
40 fabiana
# more mappings
For page redirects you can use following approach (map file will be different as well as RewriteRule expressions)
Before any work, I would recommend going through RewriteMap documentation first so you understands the tool i.e. its configuration and usage.
I hope that will be good direction for your task.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule %{REQUEST_FILENAME} !-f
RewriteRule %{REQUEST_FILENAME} !-d
RewriteBase /
RewriteRule ^/greece-escort/?$ /index.php?page=2 [NC,L]
RewriteRule ^/athens-escort/?$ /index.php?page=3 [NC,L]
RewriteRule ^/bookings/?$ /index.php?page=4 [NC,L]
RewriteRule ^/jobs/?$ /index.php?page=5 [NC,L]
RewriteRule ^/contact-us/?$ /index.php?page=6 [NC,L]
RewriteRule ^/articles/?$ /index.php?page=24 [NC,L]
RewriteRule ^/links/?$ /index.php?page=7 [NC,L]
RewriteRule ^/profile/aleena/?$ /index.php?profile=22 [NC,L]
RewriteRule ^/profile/fabiana/?$ /index.php?profile=40 [NC,L]
RewriteRule ^/profile/sabrina/?$ /index.php?profile=48 [NC,L]
RewriteRule ^/profile/suzanna/?$ /index.php?profile=69 [NC,L]
RewriteRule ^/profile/anna/?$ /index.php?profile=63 [NC,L]
RewriteRule ^/profile/sam/?$ /index.php?profile=70 [NC,L]
RewriteRule ^/profile/Larissa&Samantha/?$ /index.php?profile=61 [NC,L]
RewriteRule ^/profile/McKenzie/?$ /index.php?profile=54 [NC,L]
RewriteRule ^/profile/valery/?$ /index.php?profile=29 [NC,L]
</IfModule>
.htaccess
Anyone know how to redirect
domain/blog/208-%-top.html
To:
domain/blog/208-top.html
in Joomla?
None of the below works:
RewriteRule ^blog/208-%-top.html$ 208-top.html [R=301,L]
RewriteRule ^blog/208-\%-top.html$ 208-top.html [R=301,L]
RewriteRule ^blog/208-.*-top.html$ 208-top.html [R=301,L]
It works if: url has %20 or %25 and have below in htaccess
RewriteRule ^blog/208-%20-top.html$ 208-top.html [R=301,L]
RewriteRule ^blog/208-%25-top.html$ 208-top.html [R=301,L]
But the problem is blog post has % only. Is there any work around to fix this?
This URL:
domain.com/blog/208-%-top.html
is indeed an invalid URL and would cause HTTP 400 (Bad Request) error in your Apache logs.
As you noted too that any of these 2 URLs are valid:
domain.com/blog/208-%20-top.html
OR
domain.com/blog/208-%25-top.html
And both of them will work well with this Rewrite rule:
RewriteRule ^blog/208-\%-top\.html$ blog/208-top.html [R=301,L,NC]
Your problem may be because apache isn't properly identifying your rewrite target as a URL-path, you'll need to include the full path to fix that.
RewriteRule ^blog/208-\%-top.html$ /blog/208-top.html [R=301,L]