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.
Related
I know how to change URL in PHP but I am not an expert in WordPress.
I have this URL:
domain.com/parent-page/child-page-here/?id=SomeText
and I want this
domain.com/parent-page/child-page-here/Some Text:
I changed .htaccess but its not working here is my .htaccess code
# 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]
</IfModule>
# END WordPress
RewriteEngine On
RewriteRule ^parent-page/child-page/([0-9a-zA-Z]+) parent-page/child-page/?id=$1 [NC,L]
No need to use the .htaccess as Wordpress comes with the feature you are required. All you have to do is change the permalink as here from the admin dashboard.
#mapmalith is correct, with WordPress you can simply change the permalinks in your settings.
However, if for whatever reason you're unable to do this, then you can use the following inside your .htaccess file:
RewriteEngine On
RewriteRule ^parent-page/child-page-here/([^/]*)$ /parent-page/child-page-here/?id=$1 [L]
It will leave you with the following URL: domain.com/parent-page/child-page-here/SomeText. Just make sure you clear your cache before you test this.
Obviously you will need to rename the directories to the correct names.
I'm trying to redirect this url:
myurl.com/track/124
to this one:
myurl.com/wp-content/themes/themefolder/track.php?id=124
The parameter value 124 can be anything. I have modified the .htaccess file on the root of the server so now it has this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^track/?$ wp-content/themes/themefolder/track.php?id=$1 [QSA,R,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
However when I go to myurl.com/track/124 I 404 Not Found returned. Can anyone spot the problem and help me fix this?
Another question: Is there a way to make sure the URL does not show wp-content/themes/themefolder/track.php?id=124 and keeps is track/124
Thanks
I think you need to change
RewriteRule ^track/?$ wp-content/themes/themefolder/track.php?id=$1 [QSA,R,L]
to
RewriteRule ^track/(\d+) wp-content/themes/themefolder/track.php?id=$1 [QSA,R,L]
Try using Wordpress' built in function add_rewrite_rule
add_filter('init','my_rewrite_rules');
function my_rewrite_rules(){
add_rewrite_rule('^track/([^/]*)/?','wp-content/themes/themefolder/track.php?id=$matches[1]','top');
}
You will then need to visit your permalinks page in settings (Dashboard->Settings->Permalinks->Save Changes) in order for the added rule to take effect.
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 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.
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/