I want to show the URL
http://www.example.com/blog/feedback
as
http://www.example.com/feedback
How can I do so using .htaccess?
You will need mod_rewrite to do this.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/feedback$ /blog/feedback
</IfModule>
Have a look here for a tutorial information on mod_rewrite.
EDIT:
If you are trying to move JUST /blog/feedback to /feedback then you will have to first move your base from /app/webroot/blog/ to /app/webroot/, edit all your rules to account for it and then add your new rule. Could be done like so:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /app/webroot/
RewriteRule ^/blog/index\.php$ - [L]
RewriteRule ^/blog/feedback$ /feedback [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /blog /app/webroot/blog/index.php [L]
</IfModule>
NB: This should work, but I'm not at my work station right now so I can't check it :( If anything goes wrong it's probably a typo somewhere - let me know.
Related
I am trying to rewrite a specific PHP file GET parameter but cant seem to get things to work.
I want to rewrite http://www.example.com/meeting.php?ref=y0fpjXrrGP so it is http://www.example.com/meeting/y0fpjXrrGP
What am I mising on the below? Note I am using WordPress so adding to the existing htaccess file.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^meeting/(.*)$ meeting.php?ref=$1
</IfModule>
# END WordPress
Options -Indexes
Adding RewriteRule ^meeting/(.*)$ meeting.php?ref=$1 does not seem to work at all.
Just use this in your .htaccess file:
RewriteEngine On
RewriteRule ^meeting/([^/]*)$ /meeting.php?ref=$1 [L]
It will leave you with the URL: http://www.example.com/meeting/y0fpjXrrGP
Make sure you clear your cache when testing this.
You don't need to add that to .htaccess, if your URL is inside your Wordpress, you need to add them to the rewrite URL
Check this:
How to create custom URL routes?
Hope it helps.
So I am in a bit of a soup here.
I need to make a friendly URL.
This is the URL where I enter the search values project_name and version
localhost:8080/demo_webpages_project/retrieval.html
This is where it takes me to on submitting the values
localhost:8080/demo_webpages_project/download.php?project_name=QT&version=3.1.2
I want the URL in the following form
localhost:8080/demo_webpages_project/download/QT/3.1.2
I tried doing this using .htaccess but not really finding a solution
The following is the code for the .htaccess file.
<IfModule mod_rewrite.c>
#Turn the engine on
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#attempt1
#RewriteRule ^(.*)/$ download.php?project_name=$1&version=$1
#RewriteRule ^/(.*)$ download.php?version=$1
#attempt2
#RewriteRule ^(.*)/(.*)$ download.php?project_name=$1&version=$2 [L,NC,QSA]
#RewriteRule ^(.*)$ download.php?version=$1
</IfModule>
I would be really grateful if someone could help me out with this. This is the first time I am working on something on this and am lost.
Thanks
Have this .htaccess inside /demo_webpages_project/:
Options -MultiViews
RewriteEngine on
RewriteBase /demo_webpages_project/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ download.php?project_name=$1&version=$2 [L,QSA]
According to this article, you want a mod_rewrite (placed in an .htaccess file) rule that looks something like this:
RewriteEngine on
RewriteRule ^/news/([0-9]+)\.html /news.php?news_id=$1
And this maps requests from
/news.php?news_id=63
to
/news/63.html
Another possibility is doing it with forcetype, which forces anything down a particular path to use php to eval the content. So, in your .htaccess file, put the following:
<Files news>
ForceType application/x-httpd-php
</Files>
And then the index.php can take action based on the $_SERVER['PATH_INFO'] variable:
<?php
echo $_SERVER['PATH_INFO'];
// outputs '/63.html'
?>
I looking to parse only one specific url in htaccess in following format
https://example.com/apps/store/customdesign/shopid/2/designid/Design_10
into
https://example.com/apps/store/customdesign.php?shopid=2&designid=Design_10
I tried following things
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/customdesign$
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)$ /customdesign.php?$1=$2&$3=$4
</IfModule>
I assume you are looking for a Mod_Rewrite solution, so first make sure you have the mod rewrite extension active, then write your URL Rewrites;
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
^apps/store/customdesign/shopid/([0-9]+)/designid/([0-9A-Z_]+)$ /apps/store/customdesign.php?shopid=$1&designid=$2 [QSA,NC,L]
</IfModule>
I have provided the solution I would most-likely use if this were my problem, however you should look into RegEx as well as your specific installation and hosting permissions before continuing with URL Rewrites. Spend some time and do some research!
please help me to fix my one of wordpress problem with URL redirecting in PHP.
This is my original wordpress htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I want to create custom URL redirection here. For ex.,
I want to redirect pages,
http://example.com/b/1 > http://example.com/b?n=1
http://example.com/b/2 > http://example.com/b?n=2
i am using directory URL type (displaying URLs as directories without extensions) SEO options in wordpress settings.
inside of http://example.com/b page, I have included another php file using ‘include(‘z.php’);’ command.
Z.php is reading URL parameter comes from ‘/?n=1’ through redirected URL.
I tried below solution, but no luck..
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^b/([^/]*)$ /b/?n=$1
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Appreciate any of help.
EDIT
wordpress header file can read the translated parameters. i checked that by displaying GET parameter 'n' in title.
but it shows file not found for http://example.com/b/
i verified that, by editing http://example.com/b/ page content. non of page content displaying after rewriting.
Any help appreciated
EDIT
URL may have characters in parameter as below.
http://example.com/b/abc_1 > http://example.com/b?n=abc_1
http://example.com/b/aa_2 > http://example.com/b?n=aa_2
Thanks for Helping
At first sight it seems to me that it should be
RewriteRule ^b/([^/]*)$ /?p=$1
Wordpress doesn't know what to do with the url /b?n=X.
If you want http://example.com/b/abc_1 to work, the abc_1 part must match the slug of a wordpress post.
Additionally you have to change the settings->permalink structure to match either postname or a custom structure like /b/%postname%.
http://example.com/b/1
to
http://example.com/b?n=1
Using this
RewriteRule ^b/([0-9]+)/?$ b?n=$1 [NC,L]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^b/([0-9]+)/?$ b?n=$1 [NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Test hear
More info
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^b/([^/]*)$ /b/?n=$1
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
#add below line
RewriteRule ^b/([0-9]+)/$ http://example.com/b?n=$1 [L]
</IfModule>
I found the word press related solution for this question.
in word press all the requests are heading to index.php automatically. if we create custom rewrite to another page, that request not going through index.php. that makes wordpress unidentified request and wordpress will return page not found message.
becasue of that, we have to redirect custom rewrite to index.php instead of permalink.
i used
RewriteRule ^b/([^/]*)$ index.php?page_id=4&n=$1
this rule redirected all requests matched with rule to index page. (my page ID for /b/ is 4)
this worked successfully for me.
other solutions above worked for non wordpress situations. but i found wordpress behavior as i explained.
appreciates who tried to answer.
I am using CodeIgniter on PHP and it produces the following URLs:
http://my.domain.com/app/index.php?/admin/main/
the /index.php? is redundant so I remove it successfully with the following rewrite rule:
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ ./index.php/$1 [L]
however, I would also like to remove the /app part, but when I do so, I get a 500 error. Is this related to Code Igniter - or how do I rewrite this rule correctly (if possible)? I tried with the following:
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ ./app\/index.php/$1 [L]
Thanks!
Sorry but that is a really old way of writing the htaccess for CI if the htaccess is in the main dir of the project just use the universal htaccess code below (this does not need excluded directories and such like the old one i.e.
RewriteCond $1 !^(index\.php|images|robots\.txt)
so it is also better and like I said universal)
*It will not solve your issue with the directory but this is the best way for CI in handling the index.php removal without having to go back each time you add say a docs folder or something.
Awesome htaccess:
# Customized error messages.
ErrorDocument 404 /index.php
# Set the default handler.
DirectoryIndex index.php
# Various rewrite rules.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
Try adding rewritebase RewriteBase /Path/to/directory/DirectoryBelowApps/