This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 2 years ago.
Assume that i'm having a URL like this
example.com/demo/index.php?name=test
Now I need to rewrite the above URL like this,
example.com/demo/test
My question is, how can I achieve that by .htaccess URL rewriting?
yuppp, I got it
RewriteRule ^demo/([\w-]+)$ demo.php?id=$1
Credit to : #Abhishek Gurjar
RewriteEngine On
RewriteRule ^test/(.+) /test.php?name=$1 [L]
you must add bove code in htaccess and you can get parameter as $_GET['name']
Related
This question already has answers here:
.htaccess redirect FROM subfolder to domain name
(5 answers)
Closed 4 years ago.
I'm having problems with this kind of url
www.domain.com/.html
I have a Google Search Console issue telling me that I have problems with that url. I want to make a 301 redirect to the root of the website
From www.domain.com/.html to www.domain.com
Finally it was a 403 error (forbidden). Solved in httaccess with ErrorDocument 403 / redirection.
This question already has answers here:
How does RewriteBase work in .htaccess
(9 answers)
Closed 8 years ago.
I am working on a codeigniter site. In the .htaccess file I found this rule:
RewriteBase /
After reading up on RewriteBase, I started to wonder if this rule actually does anything within this context (if the htaccess file is placed within the root folder.) Is it safe to remove?
Even after reading the documentation and other posts, I am still very confused about what this does. Is this RewriteBase directive needed if the .htaccess file is in the root folder? WIll it behave differently within htaccess files located in folders that are not?
The RewriteBase directive specifies the URL prefix to be used for per-directory (htaccess) RewriteRule directives that substitute a relative path.
So whenever you use something that requires a relative path in the RewriteRule statements, it will use slash.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I have a combined website and web application on a domain, and I'd like to rewrite the website portion to use a more MVC framework like Symfony2.
I'd like to use the www.example.com/index.php/pagename approach which I could then replace with modrewrite to work as www.example.com/pagename.
Problem -- I am not prepared to refactor the entire web application. For example, there are sever folders with literal files that need to be accessed.
www.example.com/admin/dosomething.php
So I wondering about best ideas for rewriting index.php using something a little more attractive while preserving the file directory structure in the URLs.
Thoughts/options?
EDIT: To clarify, I want to rewrite example.com/index.php/page to something more professional while still allowing access to http://www.example.com/admin/file.php, an actual path. Looking for thoughts and best practices for that.
The default .htaccess file from Symfony Standard Edition handles this by checking for file existence before rewriting. The logic is roughly "if this request matches an existing file, don't rewrite... else, rewrite to app.php" (or in your case index.php).
It accomplishes this by using rewrite conditions combined with a rewrite rule with a - (dash) as the substitution (thus indicating that no substitution should be performed):
# If the requested filename exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [L]
# Rewrite all other queries to the front controller.
RewriteRule .? app.php [L]
If you want to let existing directories be served directly too (instead of being redirected to index.php), use the -d switch, for example by adding this at the top:
# If the requested directory exists, simply serve it (except the root, which
# should also be rewritten - the ".+" pattern requires the path to be at least
# one character long, thus ignoring the root).
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [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 10 years ago.
Improve this question
I've got some duplicate content and want to redirect to the right url (remove a part of the url and redirect)
Examples:
http://www.domain.com/en/url/1-url
http://www.domain.com/es/url/1-url
http://www.domain.com/fr/url/1-url
....
The individually should redirected to:
http://www.domain.com/en/url
http://www.domain.com/es/url
http://www.domain.com/fr/url
....
Because I have to do this for a lot of urls, I can't redirect them each manually and need a rule which detects if the url contains "/1-url" and if yes remove this part from the url - but only this part.
Would be great if a mod-rewrite hero can help me with this. I'm searching for solution over .htaccess via a rewrite rule.
Check this:
RewriteRule (\w{2})/([^/]+)/\d+-[^/]+$ /$1/$2 [R=301,L]
RewriteRule ([^/]+)/\d+-[^/]+$ /$1 [R=301,L]
If you use a imported file to each 1-url page only add redirect method to imported file.
For example your every 1-url page have header.php, add redirect function to header.php
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Shorten the URL from example.com/page.php?var=letters to example.com/letters
Using htaccess, is it possible to redirect from:
http://www.mydomain/123456
to
http://www.mydomain/myscript.php?id=123456
Any help would be much appreciated.
You can use rewrite mod :
RewriteRule ^(\d+)$ myscript.php?id=$1