Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Please guys I need help; I am having a little issue routing my URL using .htaccess.
I want a situation where I can route the url Localhost/project_folder/test/learn-the-basic-of-computing to a script on my server. Like Localhost/project_folder/test/learn-the-basic-of-computing should be routed to script.php where the slug "learn-the-basic-of-computing" will be use as a URL parameter.
So I want Localhost/project_folder/test/learn-the-basic-of-computing to be routed to script.php?slug="learn-the-basic-of-computing".
Please can someone recommend solutions on how I will construct the .htaccess rules to achieve the above explained situation
Could you please try following. Please place .htaccess inside project_folder/test/ directory.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ script.php?slug=$1 [NC,QSA,L]
Brief explanation: By using (.*) save matched regex value into buffer where it will match learn-the-basic-of-computing and later using in redirection as query string by using $1.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I believe this was answered many times, but i'm just unable to find the answer.
I'm trying to get friendly urls to work, but can't write the rewrite rules.
I need to rewrite www.mysite.com/123 to www.mysite.com/index.php?page=123
and also a page like: www.mysite.com/123/abc to www.mysite.com/index.php?page=123&secondParam=abc
Also i want to be able to link to a page like: www.mysite.com/something/index.php via www.mysite.com/something and dont rewrite it to www.mysite.com/index.php?page=something if the folder something exists on the server.
Thanks.
Try this.
Lines starting with '#' are comments and are just to document the commands.
<IfModule mod_rewrite.c>
# calls to initiate our requests Apache's Rewrite Module (you need this only once)
RewriteEngine on
# "If the requests does not point to an existing file"
RewriteCond %{REQUEST_FILENAME} !-f
# "If the requests does not point to an existing folder"
RewriteCond %{REQUEST_FILENAME} !-d
# "If the request contains a "2 subfolders" structure, redirects it silently to ..."
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?page=$1&secondParam=$2 [NC,QSA,L]
RewriteRule ^([^/]+)/?$ index.php?page=$1 [NC,QSA,L]
</IfModule>
Try this version of the last line :
RewriteRule ^(.*)/(.*)/?$ index.php?page=$1&secondParam=$2 [NC,QSA,L]
or
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ index.php?page=$1&secondParam=$2 [NC,QSA,L]
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I've set up a bit.ly link and printed it on 1000 flyers.
Somehow the bit.ly target link contains some strings which shouldn't be there (https://example.com/page/%E2%80%8E instead of https://example.com/page/)
Can I get rid of this string using rewrite rules in .htaccess?
Any help is appreciated!
When you just accidentally added the string %20%E2%80%8E in the creation of the short link, then you can just get another short link without accidentally added the string again.
Anyway, I think these .htaccess directives are what you want:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9_-]+)\%20\%E2\%80\%8E$
RewriteRule ^(.*) https://example.com/%1 [R,L]
It will redirect example.com/$anything%20%E2%80%8E into example.com/$anything
Just make sure that there's Apache HTTP Server with mod_rewrite on your web hosting account. And considered this link about the [R=301] flag: https://stackoverflow.com/a/15999177/2007055.
This code:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/([a-zA-Z0-9_-]+)/\%20\%E2\%80\%8E$
RewriteRule ^(.*) https://example.com/%1/ [R,L]
Is to redirect example.com/$anything/%20%E2%80%8E into example.com/$anything/.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
After a lot of research and help from SO members, I have cleared my first major hurdle with .htaccess.
My new .htaccess file successfully renames my index.php page to /home and takes all of the query strings attached to the links:
http://www.website.com/departments?nav=business (etc.)
and turns them into the format I want:
http://www.website.com/business
Here is my .htaccess code:
AddDefaultCharset UTF-8
RewriteEngine On
RewriteBase /
RewriteRule ^/?Home/?$ /index.php [L,NC]
RewriteRule ^([a-zA-Z-?]+)/?$ departments.php?nav=$1 [L]
If any of the above code isn't ideal, I've collected it in my research online and I'm still learning from it.
My question is, now that I have redefined the links, I know I should do a 301 redirect so that the old links don't show up as duplicates or some such with the search engines. I apologize up front for not having all the lingo down, but this is a long day two of research on this.
What is the proper code to add in order to do the redirect to keep the page SEO friendly?
Many thanks in advance!
Make you RewriteRule:
RewriteRule ^([a-zA-Z-?]+)/?$ departments.php?nav=$1 [L,R=301]
Which will make your links do a 301 redirect to your new URLs.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have some simple redirects in my htaccess file. However, the domain is going to change...I was hoping I could write something that gets the domain name?
Someone suggested:
http://%{HTTP_HOST}/
but this doesn't work.
If you want to keep the old domain and redirect all the requests to the new one, may this instruction be helpful:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old-domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.old-domain.com$ [NC]
RewriteRule ^(.*)$ http://www.new-domain.com/$1 [L,R=301]
Put the code above in a .htaccess file at the root of old-domain.
But if you are NOT worried about the old url addresses or search engines crawled your old pages, you won't need to do that, just move all your data (including .htaccess file) to your new domain
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have a problem redirecting a folder to another one.
The rule seems to "work" but it stumble at some point adding some other stuff.
Here an example:
The goal is to redirect traffic from oldfolder (not existing anymore) to newfolder.
www.domain.com/one/oldfolder/year/ --> www.domain.com/one/newfolder/year/
So i set up the following rules (first one for the canonical url):
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule ^/?$ "http\:\/\/www\.domain\.com" [R=301,L]
RewriteRule ^(.*)/oldfolder/(.*)$ $1/newfolder/$2 [R=301,L]
The problem is that it redirects to:
http://www.domain.com/home/username/public_html/www.domain.com/one/newfolder/year/
Anyone can spot the problem in the rule i wrote?
Thank you very much for your help.
Check your DocumentRoot
Check the Directory directive
Make sure you have RewriteBase / if this .htaccess file is in your document root.